from .models import Question,Choice,QuestionType,Answer
class PatchPaper:
    '''
    通过一系列转换，最后返回一个以问题对象为键，值为包含题型分数、学生选择的选项、
    是否得分的一个列表
    '''
    def __init__(self,info_dict):
        self.info_dict = info_dict

    def ConvertInfo(self):
        detail_dict = self.info_dict
        score = 0
        for key,value in detail_dict.items():
            if key == '单选题':
                value[2] = [[Question.objects.get(pk =question_id),
                             Choice.objects.get(pk = user_answer)]
                            for question_id,user_answer in value[2][:]
                            ]
            else:
                value[2] = [[Question.objects.get(pk = question_id),
                             user_answer]
                            for question_id,user_answer in value[2][:]
                            ]
        return detail_dict

    #def UpdateInfo(self,new_dict):
        
        
    
        '''
        for question_id,choice_list in detail_dict.copy().items():
            question_obj = Question.objects.get(pk = question_id)
            try:
                choice_obj = Choice.objects.get(pk = choice_list[1])
                detail_dict[question_obj] = choice_obj
            except:
                detail_dict[question_obj] = choice_list[1]
            else:
                if choice_obj.choice_text == question_obj.answer_set.all()[0].answer_text:
                    score = score + int(choice_list[0])
                    choice_list.append(int(choice_list[0]))
                else:
                    choice_list.append(question_obj.answer_set.all()[0].answer_text)
        return detail_dict
        '''









